package com.source.barcodeMachineGrantAndRecovery.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.source.barcodeMachineGrantAndRecovery.VO.BarcodeMachineRevokeVO;
import com.source.barcodeMachineGrantAndRecovery.entity.BarcodeMachineRevoke;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author Feng
 * @since 2021-02-24
 */

public interface BarcodeMachineRevokeMapper extends BaseMapper<BarcodeMachineRevoke> {

    String SELECT = "SELECT r.*,u1.`name` revokePersonName,u2.`name` returnPersonName,s.stallsName\n" +
            "FROM barcode_machine_revoke r, sys_user u1, sys_user u2, stalls s\n" +
            "WHERE r.isDelete=0 AND r.revokePersonId=u1.userId AND r.returnPersonId=u2.userId AND r.stallsId=s.stallsId\n";

    /*脚标机回收ID	脚标机ID	回收档口ID	回收时间	回收人员	送回人员	回收状态	押金退回（元）*/
    String LIKE = "\nCONCAT(IFNULL(r.revokeId, ''),IFNULL(r.barcodeMachineNumber,''),IFNULL(s.stallsName,''),IFNULL(DATE(r.revokeDate),''),IFNULL(u1.`name`,''),IFNULL(u2.`name`,''),(CASE r.status WHEN 0 THEN '正常' WHEN 1 THEN '故障' ELSE '' END),IFNULL(r.deposit,'')) LIKE CONCAT('%',#{word},'%')";

    @Select(SELECT + "AND revokeId=#{id}")
    BarcodeMachineRevokeVO getByRevokeId(@Param("id") int id);

    @Select(SELECT)
    List<BarcodeMachineRevokeVO> listAll();

    @Select(SELECT)
    Page<BarcodeMachineRevokeVO> pageAll(Page<BarcodeMachineRevokeVO> page);

    @Select(SELECT + "AND barcodeMachineNumber=#{id}")
    List<BarcodeMachineRevokeVO> listByBarcodeMachineNumber(@Param("id") int id);

    @Select(SELECT + "AND barcodeMachineNumber=#{id}")
    Page<BarcodeMachineRevokeVO> pageByBarcodeMachineNumber(@Param("id") int id, Page<BarcodeMachineRevokeVO> page);

    @Select(SELECT + "AND" + LIKE)
    List<BarcodeMachineRevokeVO> listLike(@Param("word") String s);

    @Select(SELECT + "AND" + LIKE)
    Page<BarcodeMachineRevokeVO> pageLike(@Param("word") String s, Page<BarcodeMachineRevokeVO> page);

}
